//
//  CacheGroupModel.m
//  JW_BasePorject
//
//  Created by JW on 2018/7/2.
//  Copyright © 2018年 JW. All rights reserved.
//

#import "CacheGroupModel.h"
#import <BJPlayerManagerCore/BJPlayerManagerCore.h>

@implementation CacheGroupModel

- (NSString *)groupTotalSize{
    __block int64_t totalSize= 0;
    [self.videoList enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        PMDownloadModel *model = obj;
        if (model.state == PMDownloadState_Completed) {
            totalSize = totalSize + model.videoTotalSize;
        }
    }];

    return [self ZY_getFileSizeString:totalSize];
}


- (NSString *)groupNumber{
    return [NSString stringWithFormat:@"%ld",self.videoList.count];
}



- (NSString *)ZY_getFileSizeString:(float)size {
    
    if(size >=1024*1024)//大于1M，则转化成M单位的字符串
    {
        return [NSString stringWithFormat:@"%1.2fM",size/1024/1024];
    }
    else if(size >=1024 && size<1024*1024) //不到1M,但是超过了1KB，则转化成KB单位
    {
        return [NSString stringWithFormat:@"%1.2fK",size /1024];
    }
    else//剩下的都是小于1K的，则转化成B单位
    {
        return [NSString stringWithFormat:@"%1.2fB",size];
    }
}

@end
